<?php
namespace Common\Model;

class MessageModel extends XuecheModel {

    protected $pk = 'message_id';
    protected $tableName = 'message';
    protected $fields = array(
            'message_id','member_id','re_member_id','message','status','reply_id','send_time','article_id','book_id',
            'send_ip','type','disabled'
        );


    public function Validate($data) {
        return TRUE;
    }

    //同个用户同一篇文章每天只能纠错一次
    public function checkSendOk($data){
        $where = "`member_id` = '{$data['member_id']}' AND `send_ip`='{$data['send_ip']}' AND `book_id`='{$data['book_id']}' AND `article_id`='{$data['article_id']}'";
        if($time = $this->where($where)->field('send_time')->find()){
            $time = date('Ymd',$time['send_time']);
            $now = date('Ymd',time());
            if($now <= $time){
                return false;
            }
        }
        return TRUE;

    }

    public function getList($where = '',$order = '',$offset = 0,$limit = 18){
        $data = parent::getList($where, $order, $offset, $limit);
        if($data['total'] > 0){
            $Books = new BookModel();
            foreach ($data['lists'] as $k=>$v){
                $name = $Books->getBookName($v['book_id']);
                $data['lists'][$k]['book_name'] = $name;
            }
        }
        return $data;
    }












}
